﻿using QueryBuilder.Core.Query.SqlTypes;

namespace QueryBuilder.Core.Query.Type
{
    /// <summary>
    /// 
    /// </summary>
    public class EnumStringType : ITypeMapping, IDiscripminatorType
    {
        /// <summary>
        /// 
        /// </summary>
        public const int MaxLengthForEnumString = 255;

        /// <summary>
        /// 
        /// </summary>
        private readonly System.Type enumClass;

        /// <summary>
        /// Initializes a new instance of the <see cref="EnumStringType"/> class.
        /// </summary>
        /// <param name="enumClass">The enum class.</param>
        public EnumStringType(System.Type enumClass)
            : this(enumClass, MaxLengthForEnumString)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EnumStringType"/> class.
        /// </summary>
        /// <param name="enumClass">The enum class.</param>
        /// <param name="length">The length.</param>
        public EnumStringType(System.Type enumClass, int length)
        {
            this.SqlType = SqlTypeFactory.GetString(length);
            this.enumClass = enumClass;
        }

        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get { return this.enumClass.Name; }
        }

        /// <summary>
        /// Gets the returned class.
        /// </summary>
        /// <value>The returned class.</value>
        public System.Type ReturnedClass
        {
            get { return this.enumClass; }
        }

        /// <summary>
        /// Gets or sets the type of the SQL.
        /// </summary>
        /// <value>The type of the SQL.</value>
        public SqlType SqlType { get; private set; }
    }
}